package cl.easyRestaurant.dataAccess.persistence;

// Generated 19-07-2012 01:26:30 AM by Hibernate Tools 3.3.0.GA

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.util.List;

/**
 * Home object for domain model class FormaPago.
 * @see cl.easyRestaurant.dataAccess.persistence.FormaPago
 * @author Hibernate Tools
 */
@Stateless
public class FormaPagoHome {

	private static final Log log = LogFactory.getLog(FormaPagoHome.class);

	@PersistenceContext
	private EntityManager entityManager;

	public void persist(FormaPago transientInstance) {
		log.debug("persisting FormaPago instance");
		try {
			entityManager.persist(transientInstance);
			log.debug("persist successful");
		} catch (RuntimeException re) {
			log.error("persist failed", re);
			throw re;
		}
	}

	public void remove(FormaPago persistentInstance) {
		log.debug("removing FormaPago instance");
		try {
			entityManager.remove(persistentInstance);
			log.debug("remove successful");
		} catch (RuntimeException re) {
			log.error("remove failed", re);
			throw re;
		}
	}

	public FormaPago merge(FormaPago detachedInstance) {
		log.debug("merging FormaPago instance");
		try {
			FormaPago result = entityManager.merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public FormaPago findById(String id) {
		log.debug("getting FormaPago instance with id: " + id);
		try {
			this.entityManager = javax.persistence.Persistence.createEntityManagerFactory("ToherPersistenceUnit").createEntityManager();
			FormaPago instance = entityManager.find(FormaPago.class, id);
			log.debug("get successful");
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
		finally {
			if (this.entityManager != null) {
				this.entityManager.close();
			}
		}
	}
	
	public List<FormaPago> getAll(){
		log.debug("Generando instancia de FormaPago");
		try {
			this.entityManager = javax.persistence.Persistence.createEntityManagerFactory("ToherPersistenceUnit").createEntityManager();
			//Query q = this.entityManager.createQuery("SELECT p formaPago");
			//TypedQuery<FormaPago> q = this.entityManager.createQuery("SELECT p FROM formaPago", FormaPago.class);
			TypedQuery<FormaPago> q = this.entityManager.createQuery("SELECT p FROM formaPago", FormaPago.class);
			return q.getResultList();
		} catch (RuntimeException re) {
			log.error("Error", re);
			throw re;
		}
		finally {
			if (this.entityManager != null){
				this.entityManager.close();
			}
		}
	}
}
